package business.database.maauco;

import business.coding.CandidateCenter;
import business.database.filtersemantic.CorpsFilterSQLGen;
import domain.Center
import groovy.lang.Closure;
import groovy.sql.Sql
import java.util.List;
import org.apache.log4j.Logger;

/**
 * Acceso a la tabla AU0
 * @author 53385255R
 *
 */
public class AU0DAO {

	private Sql sqlAU0;
	private Logger log;
	
	public AU0DAO(Sql sql) {
		sqlAU0 = sql;
		log = Logger.getLogger("AU0DAO");
	}
	
	/**
	 * Elimina en el IDNO en AU0
	 * @param idno
	 */
	public void delete(Integer idno) {

		sqlAU0.execute("delete * from AU0 where idno = ${idno}");
		
	}
	
	public void addNewnacionales(RegAu0Nacional reg){
		String sql="INSERT INTO AU0 (IDNO, [NO], AUTH) values(${reg.idno},${reg.no},?)"
		sqlAU0.execute(sql,[(reg.auth==null?"":reg.auth)])
	}
	
	public void addNewWos(RegAu0 reg){
		String sql="INSERT INTO AU0 (IDNO, [NO], AUTH, FULLAUTH) values(${reg.idno},${reg.no},?,?)"
		sqlAU0.execute(sql,[(reg.auth==null?"":reg.auth),(reg.fullAuth==null?"":reg.fullAuth)])
	}
	public List <RegAu0Nacional> getRegNacional(Integer idno){
		
		List<RegAu0Nacional> regs = new ArrayList<RegAu0Nacional>();
				
		String sql="SELECT AU0.IDNO, AU0.[NO],AU0.AUTH From AU0 WHERE AU0.IDNO=${idno};"
		
		sqlAU0.eachRow(sql) {
			Integer IDNO=it[0]
			Integer no=it[1]
			String auth=it[2]
			
			RegAu0Nacional reg=new RegAu0Nacional(IDNO,no,auth);
			
			regs.add(reg);
		}
		return regs;
	}
	public List <RegAu0> getRegWoS(Integer idno){
		
		List<RegAu0> regs = new ArrayList<RegAu0>();
				
		String sql="SELECT AU0.IDNO, AU0.[NO],AU0.AUTH, AU0.FULLAUTH From AU0 WHERE AU0.IDNO=${idno};"
		
		sqlAU0.eachRow(sql) {
			Integer IDNO=it[0]
			Integer no=it[1]
			String auth=it[2]
			String fullAuth=it[3]
			RegAu0 reg=new RegAu0(IDNO,no,auth, fullAuth);
			
			regs.add(reg);
		}
		return regs;
	}
}
